package ee.videorentalstore.protocols.types;

import java.util.ArrayList;

import ee.videorentalstore.UserAndProtocolManager;
import ee.videorentalstore.UserAndProtocolManagerStatus;
import ee.videorentalstore.protocols.Protocol;
import ee.videorentalstore.protocols.commands.ChangeSystemUserCommand;
import ee.videorentalstore.protocols.commands.Command;
import ee.videorentalstore.protocols.commands.GetListOfAllAvailableFilmsCommand;
import ee.videorentalstore.protocols.commands.GiveCurrentProtocolInformationCommand;
import ee.videorentalstore.protocols.commands.WhoIsInControlCommand;
import ee.videorentalstore.protocols.commands.customercommands.GetAllFilmsThatCustomerHasRentedCommand;
import ee.videorentalstore.protocols.commands.customercommands.GetCustomerBonusPointsCommand;
import ee.videorentalstore.protocols.commands.customercommands.GetHelpWhileInCustomerProtocolCommand;
import ee.videorentalstore.protocols.commands.customercommands.RentAFilmByIDCommand;
import ee.videorentalstore.utils.UserInputReader;

public class CustomerProtocol extends Protocol
{
	private ArrayList<Command> customerProtocolCommandList = new ArrayList<Command>();
	private final String COMMAND_DESCRIPTION_AND_ITS_CONTENTS_SPLITTING_CONSTANT = "----";
	
	
	public CustomerProtocol()
	{
		customerProtocolCommandList.add(new GetAllFilmsThatCustomerHasRentedCommand());
		customerProtocolCommandList.add(new GetHelpWhileInCustomerProtocolCommand());
		customerProtocolCommandList.add(new RentAFilmByIDCommand());
		customerProtocolCommandList.add(new ChangeSystemUserCommand());
		customerProtocolCommandList.add(new GetListOfAllAvailableFilmsCommand());
		customerProtocolCommandList.add(new WhoIsInControlCommand());
		customerProtocolCommandList.add(new GiveCurrentProtocolInformationCommand());
		customerProtocolCommandList.add(new GetCustomerBonusPointsCommand());
	}
	
	
	@Override
	public void runUserProtocol()
	{
		while (UserAndProtocolManager.getInstance().getUserAndProtocolManagerStatus() 
				== UserAndProtocolManagerStatus.FOLLOWING_CURRENT_PROTOCOL)
		{
			String instructionsInsertedByUserToProcess = UserInputReader.getInstance().readLine();
			
			if (!instructionsInsertedByUserToProcess.contains(COMMAND_DESCRIPTION_AND_ITS_CONTENTS_SPLITTING_CONSTANT))
			{
				instructionsInsertedByUserToProcess += COMMAND_DESCRIPTION_AND_ITS_CONTENTS_SPLITTING_CONSTANT;
			}
			
			parseCommandFromInstructionsAndExecute(instructionsInsertedByUserToProcess, customerProtocolCommandList);
		}
	}
}
